<?php
/**
 * 护理评估 模型
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-05 14:43:33
 * @version $Id$
 */

class DataHulipingguBiaodanModel extends BaseModel {

	/**
     * 返回给终端的可执行sql语句的字段名称数组
     * @var [type]
     */
    public $_field_arr = ['id','xiangmu_zuhao','biaodan_name','biaodan_id','xiangmu_name','xiangmu_leibie','xiangmu_fenzhi','beizhu','paixu','xiangmu_leixing','keshi', 'enable'];

    public function huliPinggu($user_department)
    {
    	$data_pinggu_field = "x.id as id,x.xiangmu_id as xiangmu_zuhao,b.biaodan_name as biaodan_name,b.id as biaodan_id,b.enable,m.xiangmu as xiangmu_name,x.xuanxiang as xiangmu_leibie,x.fenshu as xiangmu_fenzhi,x.xuanxiang_beizhu as beizhu,x.id as paixu,m.xuanze_leixing as xiangmu_leixing,b.keshi as keshi";

    	$query = DB::select($data_pinggu_field)
	    	->from('data_hulipinggu_biaodan as b')
	    	->join('data_hulipinggu_xiangmu as m')
	    	->on('b.id', '=', 'm.biaodan_id')
	    	->join('data_hulipinggu_xuanxiang as x')
	    	->on('m.id', '=', 'x.xiangmu_id')
	    	->where('b.keshi', 'in', [$user_department,'通用'])
	    	->and_where('b.yiyuan_id', '=', $this->yiyuan_id);
	    return $query->execute()->as_array();
    }
}
